package kandl.automation.spring.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@Configuration
public class RestTemplateConfig {

    @Bean
    @Autowired
    @SuppressWarnings("rawtypes")
    public HttpMessageConverter<?> contentConverter() {
        return new MappingJacksonHttpMessageConverter();
    }

    @Bean
    @Autowired
    public RestTemplate restTemplate(ClientHttpRequestFactory requestFactory,
                                     List<HttpMessageConverter<?>> messageConverters) {
        RestTemplate restTemplate = new RestTemplate(requestFactory);
        restTemplate.setMessageConverters(messageConverters);

        return restTemplate;
    }
}